﻿using CommunityToolkit.Mvvm.ComponentModel;
using MG.SmartHMI.Domain;
using MG.SmartHMI.Entity.DAO;

namespace MG.SmartHMI.Model
{
    public partial class InputBoxViewModel : BaseItemsControl
    {
        public InputBoxViewModel(RegisterConfig data) : base(data)
        {
        }

        public InputBoxViewModel() : base()
        {
        }

        #region InPutBox

        [ObservableProperty]
        private string inputValue;

        //partial void OnInputValueChanged(string value)
        //{
        //    if (string.IsNullOrEmpty(value)) return;
        //    ModbusCtrl.Instance.UnitWrite(RegisterData.DataType, RegisterData.Address, value);
        //}

        public override void UpdateRead()
        {
            InputValue = ModbusCtrl.Instance.UnitRead(RegisterData.DataType, RegisterData.Address).Content;
        }
        public override void UpdateWrite()
        {
            ModbusCtrl.Instance.UnitWrite(RegisterData.DataType, RegisterData.Address, InputValue);
        }

        #endregion InPutBox
    }
}